import 'package:card_swiper/card_swiper.dart';
import 'package:flutter/material.dart';
import 'package:flutter_cwhisky/common/style/colors.dart';
import 'package:flutter_cwhisky/common/style/icons.dart';
import 'package:flutter_cwhisky/common/style/style.dart';
import 'package:flutter_cwhisky/component/base/base_state_less_view.dart';
import 'package:flutter_cwhisky/component/ink/ink_well_custom.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../../bean/mall_home_entity.dart';
import '../../../common/style/dimens.dart';
import '../../text_view.dart';
import '../prefecture/other_prefecture_view.dart';
import '../prefecture/scotland_prefecture_view.dart';
import 'home_prefecture_style1_logic.dart';

class HomePrefectureStyle1Component extends BaseStateLessView<HomePrefectureStyle1Logic> {
  final logic = Get.put(HomePrefectureStyle1Logic());

  /// 独立的四个产区
  final List<MallHomeDataPrefecture>? prefecture;
  final selectColor = const Color(0xff814901);
  final selectBg = const Color(0xffFFEED7);

  HomePrefectureStyle1Component({
    super.key,
    this.prefecture,
  });

  @override
  Widget buildContent(BuildContext context) {
    return prefecture == null
        ? const SizedBox()
        : Container(
            decoration: BoxDecoration(
                color: selectBg, borderRadius: BorderRadius.circular(8.r), boxShadow: AppStyle.commonShadow),
            clipBehavior: Clip.antiAlias,
            margin: EdgeInsets.only(left: Dimens.horizontalMargin, right: Dimens.horizontalMargin, top: 12.r),
            child: Column(
              children: [
                Container(height: 44.r,  color: AppColors.white,child:            Row(
                  children: _buildTab(),
                ),),

                SizedBox(
                  height: 286.r,

                  child: Swiper(

                    controller: controller.controller,
                    itemCount: prefecture!.length,
                    itemBuilder: (context, index) => _buildSwiperItem(index),
                  ),
                )
              ],
            ),
          );
  }

  _buildSwiperItem(int index) {
    var item = prefecture![index];
    return Column(
      children: [
        Container(
          height: 36.r,
          decoration:  BoxDecoration(
              gradient: LinearGradient(
                  begin: Alignment.topCenter,
                  end: Alignment.bottomCenter,
                  colors: [selectBg, Color(0xffFFFFFF)])),
          child: Row(
            children: [
              Expanded(
                  child: Padding(
                padding: EdgeInsets.only(left: 15.r),
                child: TextView(
                  text: item.title ?? '',
                  fontSize: 12.sp,
                  fontColor: const Color(0xff935300),
                  fontWeight: FontWeight.w400,
                ),
              )),
              Row(
                children: [
                  TextView(
                    text: '更多',
                    fontSize: 12.sp,
                    fontColor: const Color(0xff935300),
                    fontWeight: FontWeight.w400,
                  ),
                  Padding(
                    padding: EdgeInsets.only(left: 4.r, right: 15.r),
                    child: Icon(
                      AppIcons.icArrowRight,
                      size: 7.r,
                      color: const Color(0xff935300),
                    ),
                  )
                ],
              )
            ],
          ),
        ),
        Expanded(
            child:Container(color: AppColors.white,child: item.name == '苏格兰'
                ? ScotlandPrefectureComponent(prefecture: item)
                : OtherPrefectureComponent(prefecture: item)),)
      ],
    );
  }

  List<Widget> _buildTab() {
    return prefecture!.map((e) => _buildTabItem(e, prefecture!.indexOf(e))).toList();
  }

  Widget _buildTabItem(MallHomeDataPrefecture item, int index) {
    bool selected = controller.index == index;
    return Flexible(
        child: InkWellCustom(
      child: Container(
        height: 44.r,
        alignment: Alignment.center,
        decoration: BoxDecoration(
            color: selected ? selectBg : AppColors.white,
            borderRadius: selected
                ? BorderRadius.only(topLeft: Radius.circular(8.r), topRight: Radius.circular(8.r))
                : BorderRadius.zero),
        child: TextView(
          text: item.name ?? '',
          fontSize: 14.sp,
          fontWeight: FontWeight.w500,
          fontColor: selected ? selectColor : AppColors.color33,
        ),
      ),
      onTap: () {
        controller.selectTab(index);
      },
    ));
  }
}
